#ifndef COMPLIE_OLINE
#include "header.cpp"
#endif
#include <ctime>
#include <chrono> 

// 正解
vector<int> twoSum(vector<int>& nums, int target) {
    int n = nums.size();
    unordered_map<int, int> _hash;
    
    for (int i = 0; i < n; i++) {
        if (_hash.count(target - nums[i])) {
            return { _hash[target - nums[i]], i };
        }
        _hash[nums[i]] = i;
    }
    return { -1, -1 };
}

int main() {
    srand(time(nullptr));
    Solution s;
    int cnt = rand() % 10000 + 1; // 测试用例个数
    // 获取当前时间点  
    auto start = std::chrono::high_resolution_clock::now();  
    for (int i = 1; i <= cnt; i++) {
        int len = rand() % 20 + 2;
        vector<int> nums(len);
        int target = rand() % 1000;
        for (int j = 0; j < len; j++) {
            nums[j] = rand() % 1000;
        }
        vector<int> true_ret = twoSum(nums, target); 
        vector<int> test_ret = s.twoSum(nums, target);// **********************************
        sort(true_ret.begin(), true_ret.end());
        if (true_ret[0] != test_ret[0]) {
            cerr << "测试通过" << i - 1 << "个测试用例" << endl;
            cerr << "用例" << i << ":[";
            for (auto x : nums) {
                cerr << x << " ";
            }
            cerr << "]" << endl;
            cerr << "target: " << target << endl;
            cerr << "预计输出: " << "[" << true_ret[0] << ", " << true_ret[1] << "]" << endl;
            cerr << "实际输出: " << "[" << test_ret[0] << ", " << test_ret[1] << "]" << endl;
            return 0;
        }
    }
    cout << "通过所有的" << cnt << "个测试用例!" << endl;
    // 获取结束时间点  
    auto end = std::chrono::high_resolution_clock::now();  
  
    // 计算两个时间点之间的持续时间  
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);  
  
    // 输出持续时间（毫秒）  
    std::cout << "运行时间: " << duration.count() << " ms" << std::endl;  
    return 0;
}


